package com.scs.application.modules.fsd.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.modules.fsd.entity.FsdChestGroup;
import com.scs.application.modules.fsd.service.ChestGroupService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description: 柜组管理
 */
@RestController
@RequestMapping("/back_front/chestGroups")
public class ChestGroupController extends CrudController<ChestGroupService, FsdChestGroup> {

    /**
     * 获取数据列表
     */
    @GetMapping(value ="/getService" )
    public RestResult getChestGroupList(@RequestParam("keyword") String keyword, @RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize") Integer pageSize){
        Map<String, Object> chestGroups= service.getChestGroupList(keyword,currentPage,pageSize);
        return RestResult.ok("get FsdChestGroup list success",chestGroups);
    }

    @PostMapping(value = "/createService")
    public RestResult createChestGroup(@RequestBody Map<String,String> map){
        Boolean ok=service.createChestGroup(map.get("chestGroupName"),map.get("remark"));
        if(ok) return RestResult.ok("保存成功！");
        return RestResult.error("保存失败！");
    }

    @PostMapping(value = "/editService")
    public RestResult editChestGroup(@RequestBody Map<String,String> map){
        Boolean ok=service.editChestGroupById(map.get("chestGroupName"),map.get("remark"),map.get("id"));
        if(ok) return RestResult.ok("保存成功！");
        return RestResult.error("保存失败！");
    }

    @GetMapping(value ="/getAllService" )
    public RestResult getAll(){
        return RestResult.ok("获取所有柜组成功",service.getAll());
    }
}
